package com.intmall.train.member.controller;

import com.intmall.train.common.context.LoginMemberContext;
import com.intmall.train.common.domain.resp.CommonPageResp;
import com.intmall.train.common.domain.resp.CommonResp;
import com.intmall.train.member.domain.req.PassengerQueryReq;
import com.intmall.train.member.domain.req.PassengerSaveReq;
import com.intmall.train.member.domain.resp.PassengerQueryResp;
import com.intmall.train.member.service.PassengerService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/passenger")
public class PassengerController {
    @Resource
    private PassengerService passengerService;

    @PostMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody PassengerSaveReq req) {
        passengerService.save(req);
        return new CommonResp<>();
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id) {
        passengerService.delete(id);
        return new CommonResp<>();
    }

    @PostMapping("/queryList")
    public CommonPageResp<PassengerQueryResp> queryList(@RequestBody PassengerQueryReq req) {
        req.setMemberId(LoginMemberContext.getId());
        return passengerService.queryList(req);
    }
}
